package com.sun.hunk.hibernate.dao;

import com.sun.hunk.hibernate.BaseHibernateDAO;
import com.sun.hunk.hibernate.domain.Link;
import com.sun.hunk.hibernate.domain.LinkTree;
import com.sun.hunk.hibernate.domain.impl.LinkImpl;
import java.util.Collection;

/**
 *
 * @author sunil
 */
public class LinkDAO extends BaseHibernateDAO<LinkImpl> {

    public LinkDAO() {
        super(LinkImpl.class);
    }

    public Link getParent(Long itemId) {
        Link item = findById(itemId);
        Collection<LinkTree> coll = item.getParents();
        LinkTree itemTree = null;
        for (LinkTree it : coll) {
            itemTree = it;
            break;
        }
        if (itemTree == null) {
            return null;
        }
        return itemTree.getParent();
    }
}
